# coding=utf-8
import msilib
import os
import sys

from cx_Freeze import setup, Executable

os.environ['TCL_LIBRARY'] = r'C:\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Python36\tcl\tk8.6'

# 中文需要显式用gbk方式编码
product_name = "huaxingzhifu"

# uuid叫通用唯一识别码，后面再卸载快捷方式中要用到
product_code = msilib.gen_uuid()

# 主程序手动命名
target_name = 'huaxingzhifu.exe'

build_exe_options = {
    "packages": ["os", "tkinter"],
    "include_files": [
        r'C:\Python36\DLLs\tcl86t.dll',
        r'C:\Python36\DLLs\tk86t.dll',
        r'favicon.ico'
    ]
}

# 快捷方式表，这里定义了三个快捷方式
shortcut_table = [
    ("DesktopShortcut",  # Shortcut
     "DesktopFolder",  # Directory_ ，必须在Directory表中
     product_name,  # Name
     "TARGETDIR",  # Component_，必须在Component表中
     "[TARGETDIR]" + target_name,  # Target
     None,  # Arguments
     None,  # Description
     None,  # Hotkey
     None,  # Icon
     None,  # IconIndex
     None,  # ShowCmd
     'TARGETDIR'  # WkDir
     )
]

msi_data = {
    "Shortcut": shortcut_table
}

bdist_msi_options = {'data': msi_data,
                     'upgrade_code': '{9f21e33d-48f7-cf34-33e9-efcfd80eed10}',
                     'add_to_path': False,
                     'initial_target_dir': r'[ProgramFilesFolder]\%s' % (product_name)}

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name="huaxingzhifu",
    version="1.0",
    description="huaxingzhifu",
    options={
        "build_exe": build_exe_options,
        "bdist_msi": bdist_msi_options
    },
    executables=[
        Executable("huaxing.py", base=base, icon="favicon.ico", targetName=target_name)]
)
